#!/bin/sh
CurrDir="$( cd "$( dirname "$0"  )" && pwd  )"
cd $CurrDir
#容器名称每个人修改为自己的（与子目录名称一致）
contrainsname="contrainsname"
contrainshave=`docker ps -a --filter name=$contrainsname --filter status=running`
if [[ $contrainshave == *$contrainsname* ]]
then
    echo "$contrainsname 容器正在运行"
	exit 0
else
	contrainshave=`docker ps -a --filter name=$contrainsname`
	if [[ $contrainshave == *$contrainsname* ]]
	then
		echo "$contrainsname 容器已经存在，开始启动"
		docker start $contrainsname
	else
		#修改自己的dll名称和端口号
		customRunCommon="dotnet ${CurrDir}/*.dll --urls=http://*:10007"
		customPreParam="-p 10007:10007"	
		echo "$contrainsname 容器不存在，开始创建"
		#修改--restart=always
		docker run --ulimit core=0 --privileged=true $customPreParam -v $CurrDir:$CurrDir -v /etc/localtime:/etc/localtime:ro --name $contrainsname -d mcr.microsoft.com/dotnet/core/aspnet:3.1-bionic $customRunCommon
	fi	
	contrainshave=`docker ps -a --filter name=$contrainsname --filter status=running`
	if [[ $contrainshave == *$contrainsname* ]]
	then
		echo "$contrainsname 容器启动成功，开始运行"
		exit 0
	else
		echo "$contrainsname 容器启动失败"
		exit 1
	fi		
fi